Replace max 2 occurrences of characters with a colon¶
re.sub(“[ ,.]”, “:”, text, 2)
Replace maximum 2 occurrences of space, comma, or dot with a colon.
import re
S = 'Python Exercises, PHP exercises.'
print(re.sub("[ ,.]", ":", S, 2))
Output:
Python:Exercises: PHP exercises.